
<div style="POSITION: relative" id="content">
  <h3>easyUI 自定义排序datagrid</h3>
  <div id="article_content" class="article_content">
    <p>如果默认的排序行为不满足你的需求,你可以自定义<span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left">datagrid排序行为.</span></p>
    <p><img src="documentation/images/1344569914_5205.png" alt=""></p>
    <p style="text-align:left">最基础的用户可以定义一个排序函数,函数名是sorter 在列上,这个函数将接受两个&#20540;和返回&#20540;将作为如下:</p>
    <p style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> valueA &gt; valueB =&gt; return 1</p>
    <p style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> valueA &lt; valueB =&gt; return -1</p>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 自定义排序代码</h4>
    <pre name="code" class="html">&lt;table id=&quot;tt&quot;&gt;&lt;/table&gt;  </pre>
    <p>
    <pre name="code" class="javascript">$('#tt').datagrid({  
    title:'Custom Sort',  
    iconCls:'icon-ok',  
    width:520,  
    height:250,  
    singleSelect:true,  
    remoteSort:false,  
    columns:[[  
        {field:'itemid',title:'Item ID',width:60,sortable:true},  
        {field:'listprice',title:'List Price',width:70,align:'right',sortable:true},  
        {field:'unitcost',title:'Unit Cost',width:70,align:'right',sortable:true},  
        {field:'attr1',title:'Attribute',width:120,sortable:true},  
        {field:'date',title:'Date',width:80,sortable:true,align:'center',  
            sorter:function(a,b){  
                a = a.split('/');  
                b = b.split('/');  
                if (a[2] == b[2]){  
                    if (a[0] == b[0]){  
                        return (a[1]&gt;b[1]?1:-1);  
                    } else {  
                        return (a[0]&gt;b[0]?1:-1);  
                    }  
                } else {  
                    return (a[2]&gt;b[2]?1:-1);  
                }  
            }  
        },  
        {field:'status',title:'Status',width:40,align:'center'}  
    ]]  
}).datagrid('loadData', data);  </pre>
    你可以从这段代码中看到,我们为date列创建了自定义的sorter ,日期的&#26684;式是&nbsp;'dd/mm/yyyy' ,可以轻松的按年月日排序.
    </p>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 下载 EasyUI示例代码:</h4>
    <div style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left; padding-left:50px"> <a href="http://jquery-easyui.googlecode.com/svn/trunk/share/tutorial/datagrid/easyui-datagrid-demo14.zip" target="_blank" class="download-link" style="color:rgb(0,0,255)">easyui-datagrid-demo.zip</a></div>
  </div>
</div>
<SCRIPT type=text/javascript>
	dp.SyntaxHighlighter.ClipboardSwf = 'documentation/js/clipboard.swf'/*tpa=http://jeasyui.com/SyntaxHighlighter/Scripts/clipboard.swf*/;
	dp.SyntaxHighlighter.HighlightAll('code');
</SCRIPT>